package com.gxa.controller.discrepancy;

import com.gxa.common.utils.R;
import com.gxa.entity.discrepancy.AccessControl;
import com.gxa.entity.discrepancy.search.AccessControlSearchMap;
import com.gxa.service.discrepancy.AccessControlService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static com.gxa.common.utils.R.error;
import static com.gxa.common.utils.R.ok;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:43:53
 */
@Api(tags = "权限管理--->门禁申请")
@RestController
@RequestMapping("/access-control")
public class AccessControlController {

    @Autowired
    private AccessControlService service;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("门禁申请列表接口")
    @GetMapping("/list")
    public R queryAll(AccessControlSearchMap map){

        return ok("successs").put("data",service.queryByPage(map)).put("homeLocations",service.homeLocations());
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("新增门禁申请接口")
    @PostMapping("/add")
    public R add(@RequestBody AccessControl device){
        if(service.save(device)){
            return ok("添加成功！");
        }
        return error("add fail");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除门禁申请接口")
    @DeleteMapping("/del/{id}")
    public R del(@PathVariable("id") Integer id){
        if(service.removeById(id)){
            return ok();
        }
        return error("del error");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑门禁申请接口")
    @PutMapping("/edit")
    public R edit(@RequestBody AccessControl device){
        if(service.updateById(device)){
            return ok();
        }
        return error("edit error");
    }
}
